//--------------------Sonic CD HUD Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
// Not all of these are used here in the HUD script, some are just used as a way for other objects to globally transmit values
private alias Object.Value0 : Object.Timer     // Initially set via a loop in the UFO script
private alias Object.Value1 : Object.BonnieTimer     // Initially set via a loop in the UFO script
private alias Object.Value3 : Object.BonnieRandom    // Initially set via a loop in the UFO script
private alias Object.Value4 : Object.BonnieAI    // Initially set via a loop in the UFO script
private alias Object.Value5 : Object.ScareTimer    // Initially set via a loop in the UFO script

private alias Object.Value6 : Object.BonnieRise    // Initially set via a loop in the UFO script
private alias Object.Value7 : Object.MoveTime    // Initially set via a loop in the UFO script
private alias Object.Value8 : Object.RandomLocation1    // Initially set via a loop in the UFO script

private alias Object.Value9 : Object.DoorTime    // Initially set via a loop in the UFO script
private alias Object.Value10 : Object.HeadShake    // Initially set via a loop in the UFO script
private alias Object.Value11 : Object.Tweak    // Initially set via a loop in the UFO script
private alias Object.Value12 : Object.LeaveTimer    // Initially set via a loop in the UFO script

// Priority
private alias 1 : PRIORITY_ACTIVE


private alias object.state : Bonnie.State

private alias Object[2].Value2 : Object.ScrollPos

event ObjectMain
//-1 is basically the ai level 0 ig

if Object[5].Type == TypeName[Blank Object]

	switch Bonnie.state
	case 15
		//instantly leave if the door is closed
		//else prepare for doom
		if LeftDoorClosed == 0
			Object.ScareTimer++
			Object.DoorTime = 400
			rand(temp2, 50)
			Object.DoorTime += temp2
			if Object.ScareTimer >= Object.DoorTime
				LDoorLocked = 1
				object.state++ //your die
				Object.ScareTimer = 0	
			end if
		else	//door
			Object.LeaveTimer++
			if Object.LeaveTimer == 10
				if Object[2].Value6 == 1
					StopSfx(SfxName[Hum])
					Object[2].Value6 = 0
					PowerUsage--
				end if

				LWindowScare = 0
				PlaySfx(SfxName[BlockL], 0)
				Object.ScareTimer = 0
				Object.LeaveTimer = 0	
				bonnie.state = 1	
			end if			
		end if
	break
	case 16	//wa
		Object.ScareTimer++
		Object.DoorTime = 300
		rand(temp2, 100)
		Object.DoorTime += temp2
		if Object.ScareTimer >= Object.DoorTime
			StopMusic()
			PlaySfx(SfxName[Jumpscare], 0)			
			object.state++
		end if
	break
	case 17
		PlayerJumpscared = 1
		if Object.BonnieRise > -100
			Object.BonnieRise -= 16
		else
			Object.BonnieRise = -100
		end if
	break	
	default
		Object.BonnieTimer++
		Object.MoveTime = 500
		rand(temp3, 50)
		Object.MoveTime += temp3
		if Object.BonnieTimer >= Object.MoveTime 
			Rand(Object.BonnieRandom, 21)
			if Object.BonnieAI > Object.BonnieRandom 
				//these align with the cameras he goes to
				//state 10 is cam 10
				//15+ is at the office watch out

					if Object[6].value1 == bonnie.state
						object[6].alpha = 355
					end if

					//dining
					rand(object[6].value12 , 4)
					rand(Object.RandomLocation1, 8)


					switch Bonnie.state
					case 0	//showstage
						Bonnie.state = 1
					break
					case 1	//dinig room
						if Object.RandomLocation1 >= 2
							Bonnie.state = 4
						else
							Bonnie.state = 2
						end if
					break		
					case 2	//backstage
						Bonnie.state = 1
					break	
					case 4	//left hall
						if Object.RandomLocation1 >= 2
							Bonnie.state = 5
						else
							Bonnie.state = 6
						end if
					break						
					case 5	//closet
						//back to hall or corner
						if Object.RandomLocation1 >= 2
							Bonnie.state = 6
						else
							Bonnie.state = 4
						end if
					break		
					case 6	//corner
						LWindowScare = 1

						if Object[2].Value5 == 1
							StopSfx(SfxName[Hum])
							Object[2].Value5 = 0
							PowerUsage--
						end if
						object.alpha = 0
						Bonnie.state = 15
					break							
					end switch	

					if Object[6].value1 == bonnie.state
						object[6].alpha = 355
					end if	
					PlaySfx(SfxName[Deep Steps], 0)	

			end if
			Object.BonnieTimer = 0	
		end if
	break
	end switch
end if	
end event

event ObjectDraw

//	DrawNumbers(0, 32, 96, Bonnie.state, 3, 8, 0)

//	DrawNumbers(0, 64, 96, Object.RandomLocation1, 3, 8, 0)


	if Object.Tweak == 1
		rand(Object.HeadShake, 6)
	end if	


//	DrawNumbers(0, 96, 96, Object.HeadShake, 3, 8, 0)


	switch Bonnie.State 
	case 15
	case 16
		if object.alpha < 255
			object.alpha += 8
		end if		
		object.inkeffect = 2
		DrawSpriteScreenFX(12, FX_INK,Object.ScrollPos, 0)
	break
	case 17
		object.drawOrder = 5
		if Object.Tweak == 0
			temp0 = screen.xsize
			temp0 -= screen.xsize
			if Object[11].HeadShake < temp0
				Object[11].HeadShake += 20
			else
				Object.Tweak = 1
			end if
		end if	

		temp1 = Screen.xsize
		temp1 /= 2
		temp1 -= 140


		temp2 = temp1
		temp2 += Object.HeadShake


		
		DrawSpriteScreenFX(10, FX_SCALE, temp2, Object.BonnieRise)	//body
		DrawSpriteScreenFX(11, FX_SCALE, temp2, Object.BonnieRise)	//head
	break
	end switch



end event


event ObjectStartup
	
	LoadSpriteSheet("FNAF/Jumpscares.gif")
	
	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[11].Type = TypeName[Bonnie]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[11].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[11].DrawOrder = 3

	Object[11].HeadShake = -200

	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	SpriteFrame(-10, 270, 320, 87, 703, 936)
	SpriteFrame(48, 70, 204, 250, 819, 685)	//11	

	SpriteFrame(-33, 46, 125, 188, 813, 1)	

end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(0, 0, 24, 16, 206, 58)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
